package com.woniuxy.controller;

import com.woniuxy.Exception.serviceException;
import com.woniuxy.dao.DepartmentsDao;
import com.woniuxy.dao.PrincipalDao;
import com.woniuxy.entity.*;

import com.woniuxy.service.DepartmentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DepartmentsController {


    @Autowired
    DepartmentsService departmentsService;
    @PostMapping("/departments/{pageIndex}/{pageSize}")
public ResponseResult getAll(@PathVariable("pageIndex") int pageIndex, @PathVariable("pageSize") int pageSize,
                               @RequestBody Departments  departments) {

        PageBean<Departments> departmentses = departmentsService.getAllDepartments(departments, pageIndex, pageSize);
        ResponseResult responseResult = new ResponseResult(200, "ok", departmentses);
        return responseResult;
}

    @GetMapping("/departments")
    public List<Departments> getAll() {
        return departmentsService.getAll();
    }

@DeleteMapping("/departments/{departmentsId}")
    public void removeDepartments(@PathVariable("departmentsId")String  departmentsId){
departmentsService.removeDepartments(departmentsId);

}

@PutMapping("/departments")
    public void upDepartments( @RequestBody Departments  departments){

        departmentsService.updateDepartments(departments);
    }

@PostMapping("/departments")
    public  void  insertDepartments(@RequestBody Departments  departments){

   departmentsService.addDepartments(departments);

}




}
